﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Company
{
    public partial class CompanyGoodsList_ps_DZ : BasePage
    {
        HZ.Supervise.Model.View.HospitalProcureCatalog procata = new HZ.Supervise.Model.View.HospitalProcureCatalog();

        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_User iu = BLLFactory.BLL_User();
        KeyOperationLogJG kj;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (CurrentAccount.GetUser().Org.Area.AreaID != Constants.CURRENT_DEPLOY_AREAID)
                {
                    ddlCity.SelectedValue = CurrentAccount.GetUser().Org.Area.AreaID;
                    ddlCity.Enabled = false;
                } 
                //绑定列表数据
                CompanyGoodsList_ps_DataBind();
            }
        }

        /// <summary>
        /// 数据绑定方法 
        /// </summary>
        private void CompanyGoodsList_ps_DataBind()
        {
            int t = 0;

            procata.CompanyID_PS = Request.QueryString["Companyid_PS"];

            if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            {
                //hospro.AreaID = AreaControl1.SelectedAreaID;
                procata.AreaID = ddlCity.SelectedValue;
            }

            procata.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(txtProduceCompany_SC.Text.Trim());
            procata.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(txtOutLook.Text.Trim());
            procata.Unit = HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim());
            procata.GoodsID = HZ.Supervise.DAL.DAL_Helper.Replace(txtGoodsID.Text.Trim());
            procata.RegName = HZ.Supervise.DAL.DAL_Helper.Replace(txtRegName.Text.Trim());
            procata.Brand = HZ.Supervise.DAL.DAL_Helper.Replace(txtBrand.Text.Trim());
            procata.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.Trim());
            procata.GoodsName = HZ.Supervise.DAL.DAL_Helper.Replace(tGoodsName.Text.Trim());
            System.Data.DataTable dt = iEC.GetCompanyGoodsList_ps_DZ(procata, this.AspNetPager_CompanyGoodsList_ps.CurrentPageIndex, AspNetPager_CompanyGoodsList_ps.PageSize, out t);
            AspNetPager_CompanyGoodsList_ps.RecordCount = t;
            gvwPSLInfo.PageSize = AspNetPager_CompanyGoodsList_ps.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();
            AddLog(string.Format("查询配送企业[{0}]有关低值耗材配送数据!(配送企业列表)", Request["comname"]));
        }

        /// <summary>
        /// 数据查询事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager_CompanyGoodsList_ps.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 分页事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyGoodsList_ps_PageChanged(object sender, EventArgs e)
        {
            CompanyGoodsList_ps_DataBind();
        }

        /// <summary>
        /// 导出数据事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;
            HZ.Supervise.Model.View.HospitalProcureCatalog procata = new HZ.Supervise.Model.View.HospitalProcureCatalog();
            procata.CompanyID_PS = Request.QueryString["Companyid_PS"];
            if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            {
                //hospro.AreaID = AreaControl1.SelectedAreaID;
                procata.AreaID = ddlCity.SelectedValue;
            }
            procata.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(txtProduceCompany_SC.Text.Trim());
            procata.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(txtOutLook.Text.Trim());
            procata.Unit = HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.Trim());
            procata.GoodsID = HZ.Supervise.DAL.DAL_Helper.Replace(txtGoodsID.Text.Trim());
            procata.RegName = HZ.Supervise.DAL.DAL_Helper.Replace(txtRegName.Text.Trim());
            procata.Brand = HZ.Supervise.DAL.DAL_Helper.Replace(txtBrand.Text.Trim());
            procata.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.Trim());
            procata.GoodsName = HZ.Supervise.DAL.DAL_Helper.Replace(tGoodsName.Text.Trim());
            System.Data.DataTable dt = iEC.GetCompanyGoodsList_ps_DZ(procata, 0, 0, out t);
            AddLog(string.Format("导出配送企业[{0}]有关低值耗材配送数据成功!(配送企业列表)", Request["comname"]));
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }

        /// <summary>
        /// 返回事件 
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnFinish_Click(object sender, EventArgs e)
        {
            HZ.Web.WebUtil.RedirectByScript("CompanyList_PS_DZ.aspx");
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="msg"></param>
        private void AddLog(string msg)
        {
            kj = new KeyOperationLogJG();
            kj.OperationLogSerialID = Guid.NewGuid().ToString();
            kj.Operator = CurrentAccount.GetUser().UserID;
            kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
            kj.OperateTime = DateTime.Now;
            kj.OperateMessage = msg;
            iu.AddKeyOperationLog(kj);
        }
    }
}